/*
 ============================================================================
 Name		: WapCharge.h
 Author	  : ceze
 Version	 : 1.0
 Copyright   : FlashBox for ver.Zhongyou(���ʰ�)
 Description : CWapCharge wap计费接口
 ============================================================================
 */

#ifndef WAPCHARGE_H
#define WAPCHARGE_H

#include <e32base.h>	// For CActive, link against: euser.lib
#include <e32std.h>		// For RTimer, link against: euser.lib
#include "WebClientEngine.h"

/**
 * 定购结果监听接口
 */
class MWapChargeObserver
{
public:
	virtual void IsCharged (TBool aCharged, TInt aSum, TInt aCurrentNum ) = 0;
};

class CWapCharge : public CActive, MWebClientObserver
{
public:
	// Cancel and destroy
	~CWapCharge ();

	// Two-phased constructor.
	static CWapCharge* NewL ();

	// Two-phased constructor.
	static CWapCharge* NewLC ();

public:
	// New functions
	// Function for making the initial request
	void StartL (TTimeIntervalMicroSeconds32 aDelay );

	//开始点播
	TBool ChargeL(const TDesC8 &aChargeUri );

protected:
	////////////////////MWebClientObserver接口函数//////////////
	/**
	 * WebClientEvent()
	 * Called when event occurs in CWebClientEngine.
	 * @param aEventDescription: A event in textual format, e.g.
	 *                           "Transaction Successful"
	 */
	void WebClientEvent (const TInt aEvent, TInt aSessionId,/*const TDesC& aEventDescription,*/
	TInt aCode = 0 );

	/**
	 * WebClientHeaderReceived()
	 * Called when HTTP header is received.
	 * @param aHeaderData: Header field name and value
	 */
	void WebClientHeaderReceived (const TDesC8& aHeaderFiled, const TDesC8& aHeaderVal, TInt aSessionId );

	/**
	 * WebClientBodyReceivedComplete()
	 * Called when a part of the HTTP body is received.
	 * @param aBodyData:  Part of the body data received. (e.g. part of
	 *                    the received HTML page)
	 */
	void WebClientBodyReceivedComplete (const TDesC8& aBodyData, TInt aSessionId );

	/**
	 * 
	 */
	void ClientBodyReceived (const TDesC8& aBodyData, TBool aIsLast );

private:
	// C++ constructor
	CWapCharge();

	// Second-phase constructor
	void ConstructL ();

private:
	// From CActive
	// Handle completion
	void RunL ();

	// How to cancel me
	void DoCancel ();

	// Override to handle leaves from RunL(). Default implementation causes
	// the active scheduler to panic.
	TInt RunError (TInt aError );
	
	//解析定购计费
	void ParsePayL(const TDesC8& aDes);

	//判断页面信息是否正确
	void FindErrorL(const TDes8& aDes, TInt &errCode);
	
	//处理Url连接(将&amp替换成&
	void ParseURL(TDes8 &aUrl);
	
	
private:
	enum TWapChargeState
	{
		EUninitialized, // Uninitialized
		EInitialized, // Initalized
		EError
	// Error condition
	};

private:
	TInt iState; // State of the active object
	RTimer iTimer; // Provides async timing service
	
	HBufC8 *m_pChargeUrl;
	TBool	m_isSod;//是否已点播
	TInt	m_chargeTryTimes;//尝试次数
	TBool	m_isRedirect; //302跳转
	
	const static TInt KSessionRedirect = 0x1100;

};

#endif // WAPCHARGE_H
